package com.lc.cms.contoller;

import com.lc.cms.dto.UserDepartmentDto;
import com.lc.cms.dto.UserPagingParameterDto;
import com.lc.cms.dto.UserRoleDto;
import com.lc.cms.model.UserModel;
import com.lc.cms.service.IUserService;
import com.lc.cms.utils.ResponseResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("user")
@Log4j2
public class UserController {

    private final IUserService userService;

    @Autowired
    public UserController(IUserService userService) {
        this.userService = userService;
    }

    @RequestMapping("create")
    public ResponseResult create(UserModel user) {
        Long start = new Date().getTime();
        ResponseResult responseResult = userService.create(user);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("update")
    public ResponseResult update(UserModel user) {
        Long start = new Date().getTime();
        ResponseResult responseResult = userService.update(user);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("updatePassword")
    public ResponseResult updatePassword(UserModel user) {
        Long start = new Date().getTime();
        ResponseResult responseResult = userService.updatePassword(user);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("delete")
    public ResponseResult delete(int id) {
        Long start = new Date().getTime();
        ResponseResult responseResult = userService.delete(id);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("updateUserDepartment")
    public ResponseResult updateUserDepartment(UserDepartmentDto user) {
        Long start = new Date().getTime();
        ResponseResult responseResult = userService.updateUserDepartment(user);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("updateUserRole")
    public ResponseResult updateUserRole(UserRoleDto user) {
        Long start = new Date().getTime();
        ResponseResult responseResult = userService.updateUserRole(user);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("getListPagingByCondition")
    public ResponseResult getListPagingByCondition(UserPagingParameterDto user) {
        Long start = new Date().getTime();
        ResponseResult responseResult = userService.getListPagingByCondition(user);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }
}
